package com.smartshopping.engine;

public class SearchEngine {

	public SearchEngine() {
	}

	// EFFECTS: return true when input is a sub-string of target
	public boolean checkHalf(String input, String target) {
		input = input.toLowerCase();
		target = target.toLowerCase();
		return target.contains(input.subSequence(0, input.length() - 1));
	}

	// EFFECTS: return true when target contains one or more characters which
	// are belong to input
	public boolean checkFull(String input, String target) {
		for (int i = 0; i < input.length(); i++) {
			boolean result = target.contains(input.subSequence(i, 1));
			if (result == true)
				return result;
		}
		return false;
	}

	public boolean checkIsOktoPutOnList(String halfS, String fullS,
			String target) {
		if (halfS == null)
			halfS = "";
		if (fullS == null)
			fullS = "";
		if (fullS.matches("") && halfS.matches(""))
			return true;
		if (fullS.matches("") && checkHalf(halfS, target))
			return true;
		if (halfS.matches("") && checkFull(fullS, target))
			return true;
		return false;
	}
}
